home *** CD-ROM | disk | FTP | other *** search
/ Winzipper / Winzipper_ISO.iso / programming / oracle7 7.2 / DB / UTIL72 / EXAMP8.SQL < prev    next >
Encoding:
Text File  |  1995-05-18  |  1.6 KB  |  49 lines

  1. rem 
  2. rem $Header: examp8.sql 7020100.1 94/09/28 16:39:50 cli Generic<base> $ 
  3. rem 
  4. Rem  Copyright (c) 1991 by Oracle Corporation 
  5. Rem    NAME
  6. Rem      examp8.sql - <one-line expansion of the name>
  7. Rem    DESCRIPTION
  8. Rem      <short description of component this file declares/defines>
  9. Rem    RETURNS
  10. Rem 
  11. Rem    NOTES
  12. Rem      <other useful comments, qualifications, etc.>
  13. Rem    MODIFIED   (MM/DD/YY)
  14. Rem     rvasired   05/12/92 -  Creation 
  15. /*
  16. ** This block calculates the total wages (salary plus commission)
  17. ** paid to employees in department 20.  It also determines how
  18. ** many of the employees have salaries higher than $2000, and how
  19. ** many have commissions larger than their salaries.
  20. **
  21. ** Copyright (c) 1989,1992 by Oracle Corporation
  22. */
  23.  
  24. DECLARE
  25.     CURSOR emp_cursor(dnum NUMBER) IS
  26.         SELECT sal, comm FROM emp WHERE deptno = dnum;
  27.     total_wages   NUMBER(11,2) := 0;
  28.     high_paid      NUMBER(4) := 0;
  29.     higher_comm      NUMBER(4) := 0;
  30. BEGIN
  31.     /* The number of iterations will equal the number of rows *
  32.      * returned by emp_cursor.                                */
  33.     FOR emp_record IN emp_cursor(20) LOOP
  34.         emp_record.comm := NVL(emp_record.comm, 0);
  35.         total_wages := total_wages + emp_record.sal +
  36.             emp_record.comm;
  37.         IF emp_record.sal > 2000.00 THEN
  38.             high_paid := high_paid + 1;
  39.         END IF;
  40.         IF emp_record.comm > emp_record.sal THEN
  41.             higher_comm := higher_comm + 1;
  42.         END IF;
  43.     END LOOP;
  44.     INSERT INTO temp VALUES (high_paid, higher_comm,
  45.         'Total Wages: ' || TO_CHAR(total_wages));
  46.     COMMIT;
  47. END;
  48. /
  49.